define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lesson/index' + location.search,
                    add_url: 'lesson/add',
                    edit_url: 'lesson/edit',
                    del_url: 'lesson/del',
                    multi_url: 'lesson/multi',
                    table: 'lesson',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'category_ids', title: __('Category_ids')},
                        {field: 'topimage', title: __('Topimage'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'lesson_date', title: __('Lesson_date'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'lesson_fee', title: __('Lesson_fee'), operate:'BETWEEN'},
                        {field: 'lesson_start_time', title: __('Lesson_start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'lesson_end_time', title: __('Lesson_end_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'lesson_address', title: __('Lesson_address')},
                        {field: 'indexswitch', title: __('Indexswitch'), searchList: {"0":__('Indexswitch 0'),"1":__('Indexswitch 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh')},
                        // {field: 'content', title: __('Content')},
                        {field: 'lesson_people', title: __('Lesson_people')},
                        {field: 'signup_num', title: __('Signup_num')},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange'},
                        // {field: 'group_list', title: __('Group_list')},
                        // {field: 'category_list', title: __('Category_list'), searchList: {"1":__('Category_list 1'),"2":__('Category_list 2'),"3":__('Category_list 3')}, formatter: Table.api.formatter.normal},
                        {field: 'statusswitch', title: __('Statusswitch'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'lessongroup.id', title: __('Lessongroup.id')},
                        {field: 'lessongroup.name', title: '所属分组'},
                        // {field: 'lessongroup.image', title: __('Lessongroup.image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'lessongroup.sort', title: __('Lessongroup.sort')},
                        // {field: 'lessongroup.status', title: __('Lessongroup.status')},
                        // {field: 'lessongroup.createtime', title: __('Lessongroup.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});